home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Technology Seed / Jan. '98 ATS.toast / NavServices1.0b3 / Navigation Services SDK / Examples / Sampler / Sampler ƒ / document.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-12  |  17.9 KB  |  705 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        document.c
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #pragma segment DocSeg
  9.  
  10. #ifndef __DRAG__
  11. #include <Drag.h>
  12. #endif
  13.  
  14. #ifndef __TOOLUTILS__
  15. #include <ToolUtils.h>
  16. #endif
  17.  
  18.  
  19. #ifndef Common_Defs
  20. #include "Common.h"
  21. #endif
  22.  
  23. #ifndef __MYSPRINTF__
  24. #include "Mysprintf.h"
  25. #endif
  26.  
  27. #ifndef __NAVIGATION__
  28. #include "Navigation.h"
  29. #endif
  30.  
  31. const             printID = -8192;    // string rsrc ID if print driver name
  32. const OSType    strType = 'STR ';    // string resource type
  33.  
  34. extern short         gDocumentCount;
  35. extern Document*    gDocumentList[kMaxDocumentCount];
  36. extern short         gQuitting;
  37. extern short        gCanUndoDrag;
  38. extern WindowPtr    gUndoFrontmost, gLastFrontmost;
  39. extern Boolean        gCanDrag;
  40. extern Boolean        gNavServicesExists;
  41.  
  42. extern pascal OSErr MyTrackingHandler(short message, WindowPtr theWindow, void* handlerRefCon, DragReference theDrag);
  43. extern pascal OSErr MyReceiveDropHandler(WindowPtr theWindow, unsigned long handlerRefCon, DragReference theDrag);
  44.  
  45. void PositionDocumentParts(Document* theDocument);
  46. void DoDrawGrowIcon(WindowPtr theWindow);
  47.  
  48. DragReceiveHandlerUPP     receiveHandler;
  49. DragTrackingHandlerUPP     trackingHandler;
  50. DragSendDataUPP         sendHandler;
  51.  
  52. pascal void myventProc(const     NavEventCallbackMessage callBackSelctor, 
  53.                                                 NavCBRecPtr callBackParms, 
  54.                                                 NavCallBackUserData callBackUD);
  55. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting);
  56.  
  57.  
  58. // **********************************************************************
  59. // *
  60. // *    AddText()
  61. // *
  62. // **********************************************************************
  63. void AddText(Document* theDocument, Ptr text, long len)
  64. {
  65.     if (theDocument->theTE != NULL)
  66.         {
  67.         TEInsert(text,len,theDocument->theTE);
  68.         theDocument->dirty = true;
  69.         TESelView(theDocument->theTE);
  70.         AdjustScrollBar((Document*)GetWRefCon(theDocument->theWindow));
  71.         }
  72. }
  73.  
  74.  
  75. // **********************************************************************
  76. // *
  77. // *    AdjustDocumentView()
  78. // *
  79. // **********************************************************************
  80. void AdjustDocumentView(Document* theDocument)
  81. {    
  82.     short    delta, docTop, docTopLimit;
  83.  
  84.     delta = (theDocument->vScrollPos - GetControlValue(theDocument->vScroll)) * ScrollResolution;
  85.  
  86.     if (delta && theDocument->theTE)
  87.         {
  88.         if (delta > 0)
  89.             {
  90.             docTop = (**(theDocument->theTE)).destRect.top;
  91.             docTopLimit = (**(theDocument->theTE)).viewRect.top + TopMargin;
  92.             if (docTop + delta > docTopLimit)
  93.                 delta = docTopLimit - docTop;
  94.             }
  95.         TEScroll(0,delta,theDocument->theTE);
  96.         theDocument->vScrollPos = GetControlValue(theDocument->vScroll);
  97.         }
  98. }
  99.  
  100.  
  101. // **********************************************************************
  102. // *
  103. // *    AdjustScrollBar()
  104. // *
  105. // **********************************************************************
  106. void AdjustScrollBar(Document* theDocument)
  107. {    
  108.     short        docTop, docBottom, viewTop, viewBottom;
  109.     short        offTop, offBottom;
  110.     RgnHandle    viewRgn;
  111.  
  112.     if (theDocument->theTE != NULL)
  113.         {
  114.         docTop = (**(theDocument->theTE)).destRect.top;
  115.         docBottom = docTop + TEGetHeight(32767,0,theDocument->theTE);
  116.         viewTop = (**(theDocument->theTE)).viewRect.top;
  117.         viewBottom = (**(theDocument->theTE)).viewRect.bottom;
  118.     
  119.         offTop = ((viewTop - (docTop - TopMargin)) + ScrollResolution - 1) / ScrollResolution;
  120.         offBottom = (((docBottom + BottomMargin) - viewBottom) + ScrollResolution - 1) / ScrollResolution;
  121.         if (offTop < 0)
  122.             offTop = 0;
  123.         if (offBottom < 0)
  124.             offBottom = 0;
  125.     
  126.         theDocument->vScrollPos = offTop;
  127.     
  128.         SetControlMaximum(theDocument->vScroll,offTop + offBottom);
  129.         SetControlValue(theDocument->vScroll,offTop);
  130.     
  131.         viewRgn = NewRgn();
  132.         RectRgn(viewRgn,&(**(theDocument->theTE)).viewRect);
  133.         SectRgn(viewRgn,theDocument->hiliteRgn,theDocument->hiliteRgn);
  134.         DisposeRgn(viewRgn);
  135.         }
  136. }
  137.  
  138.  
  139. // **********************************************************************
  140. // *
  141. // *    PositionDocumentParts()
  142. // *
  143. // **********************************************************************
  144. void PositionDocumentParts(Document* theDocument)
  145. {    
  146.     Rect globalBounds = theDocument->theWindow->portRect;
  147.     Rect theRect;
  148.  
  149.     // size the vertical scrollbar:
  150.     SizeControl(theDocument->vScroll,kScrollBarWidth,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+4);
  151.     MoveControl(theDocument->vScroll,globalBounds.right+2 - kScrollBarPos,-1);
  152.  
  153.     // size the horizontal scrollbar:
  154.     SizeControl(theDocument->hScroll,(globalBounds.right - globalBounds.left - kScrollBarPos)+4,kScrollBarWidth);
  155.     MoveControl(theDocument->hScroll,-1,(globalBounds.bottom - globalBounds.top - kScrollBarPos)+2);
  156.  
  157.     theRect = globalBounds;
  158.     theRect.right  -= 15;
  159.     theRect.bottom -= 15;
  160.     (**(theDocument->theTE)).viewRect = theRect;
  161.     (**(theDocument->theTE)).destRect.right = theRect.right - RightMargin;
  162.     TECalText(theDocument->theTE);
  163. }
  164.  
  165.  
  166. void SizeDocWindow(Document* theDocument)
  167. {
  168.     short length = 0;
  169.     short width = 0;
  170.     if (theDocument->fPict != NULL)
  171.         {
  172.         if ((**((PicHandle)theDocument->fPict)).picFrame.right >= qd.screenBits.bounds.right)
  173.             width = qd.screenBits.bounds.right-40;
  174.         else
  175.             width = (**((PicHandle)theDocument->fPict)).picFrame.right;
  176.  
  177.         if ((**((PicHandle)theDocument->fPict)).picFrame.bottom >= qd.screenBits.bounds.bottom)
  178.             length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;
  179.         else
  180.             length = (**((PicHandle)theDocument->fPict)).picFrame.bottom;
  181.         }
  182.     else
  183.         {
  184.         length = qd.screenBits.bounds.bottom-10-LMGetMBarHeight()-27;    
  185.         width = kWindowWidth;
  186.         }
  187.     SizeWindow(theDocument->theWindow,width,length,true);
  188. }
  189.  
  190.  
  191. // **********************************************************************
  192. // *
  193. // *    NewDocument()
  194. // *
  195. // **********************************************************************
  196. Document* NewDocument(Boolean newDocAsPICT)
  197. {    
  198.     OSErr            theErr = noErr;
  199.     Document*        theDocument;
  200.     WindowPtr        theWindow;
  201.     Rect            theRect = {0,0,16,16};
  202.     TextStyle        theStyle;
  203.     TEStyleHandle    theStyleHandle;
  204.     Point            thePoint;
  205.     Rect            theSize;
  206.     short            length = 0, width = 0;
  207.     Str255            windTitle;
  208.     short            offset;
  209.     Rect            bounds;
  210.  
  211.     if (gDocumentCount == kMaxDocumentCount)
  212.         return ((Document*)0L);
  213.         
  214.     theDocument = gDocumentList[gDocumentCount++] = (Document*)NewPtr(sizeof(Document));
  215.     
  216.     // create the window
  217.     offset = gDocumentCount-1;
  218.     theDocument->theWindow = theWindow = NewCWindow(0L,&theSize,(unsigned char*)"\p",false,zoomDocProc,(WindowPtr)-1L,true,0L);
  219.     MoveWindow(theDocument->theWindow,(10+(offset*20)),(27+(offset*20)+LMGetMBarHeight()),true);
  220.     
  221.     bounds = theWindow->portRect;
  222.  
  223.     // setup the window title
  224.     Mysprintf((StringPtr)windTitle,(StringPtr)"untitled %d",gDocumentCount);
  225.     MyC2PStr((char*)windTitle);
  226.     SetWTitle(theDocument->theWindow,windTitle);
  227.     
  228.     SetWRefCon(theWindow,(long)theDocument);
  229.  
  230.     SetPort(theWindow);
  231.     thePoint.v = bounds.top;
  232.     thePoint.h = bounds.left;
  233.  
  234.     LocalToGlobal(&thePoint);
  235.     if (thePoint.h < 10)
  236.         MoveWindow(theWindow,InitialH,InitialV,false);
  237.  
  238.     if (newDocAsPICT)
  239.         {
  240.         theDocument->theTE = NULL;
  241.         theDocument->fPict = NULL;
  242.         theDocument->fPictLength = 0;
  243.         theDocument->fHeader = NULL;
  244.         }
  245.     else
  246.         {
  247.         theDocument->fPict = NULL;
  248.  
  249.         SizeDocWindow(theDocument);
  250.  
  251.         theDocument->vScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  252.         theDocument->hScroll = NewControl(theWindow,&theRect,(ConstStr255Param)"\p",true,0,0,0,scrollBarProc,(long)theDocument);
  253.  
  254.         theDocument->theTE = TEStyleNew(&theRect,&theRect);
  255.         (**(theDocument->theTE)).destRect.top    = TopMargin;
  256.         (**(theDocument->theTE)).destRect.left   = LeftMargin;
  257.         (**(theDocument->theTE)).destRect.bottom = 32767;
  258.         
  259.         TEAutoView(true,theDocument->theTE);
  260.  
  261.         TEFeatureFlag(teFOutlineHilite,teBitSet,theDocument->theTE);
  262.  
  263.         theDocument->hiliteRgn = NewRgn();
  264.         theStyleHandle = TEGetStyleHandle(theDocument->theTE);
  265.         (**theStyleHandle).teRefCon = (long)theDocument;
  266.  
  267.         theStyle.tsFont = 21;
  268.         theStyle.tsSize = 12;
  269.         TESetStyle(doFont + doSize,&theStyle,false,theDocument->theTE);
  270.         
  271.         theDocument->vScrollPos = 0;
  272.         theDocument->undoDragText = 0L;
  273.         
  274.         PositionDocumentParts(theDocument);
  275.  
  276.         if (gCanDrag && theDocument->theTE != NULL)
  277.             {
  278.             receiveHandler = NewDragReceiveHandlerProc(&MyReceiveDropHandler);
  279.             trackingHandler = NewDragTrackingHandlerProc(&MyTrackingHandler);
  280.             
  281.             theErr = InstallReceiveHandler(receiveHandler,theWindow,(void*)theDocument);
  282.             theErr = InstallTrackingHandler(trackingHandler,theWindow,(void*)theDocument);
  283.             }
  284.         }
  285.     
  286.     theDocument->fRefNum = 0;
  287.     theDocument->dirty = false;
  288.     
  289.     return theDocument;
  290. }
  291.  
  292.  
  293. // **********************************************************************
  294. // *
  295. // *    OpenAskSaveChanges()
  296. // *
  297. // **********************************************************************
  298. NavAskSaveChangesResult OpenAskSaveChanges(unsigned char* docName, Boolean quitting)
  299. {
  300.     OSStatus                theStatusErr     = noErr;
  301.     OSErr                     theErr             = noErr;
  302.     NavAskSaveChangesResult    reply             = 0;
  303.     NavAskSaveChangesAction    action             = 0;
  304.     NavEventUPP                eventUPP = NewNavEventProc(myEventProc);
  305.     NavDialogOptions        dialogOptions;
  306.     
  307.     if (quitting)
  308.         action = kNavSaveChangesQuittingApplication;
  309.     else
  310.         action = kNavSaveChangesClosingDocument;
  311.         
  312.     BlockMoveData(docName,dialogOptions.savedFileName,docName[0]+1);
  313.     GetIndString(dialogOptions.clientName,rAppStringsID,sApplicationName);
  314.  
  315.     theErr = NavAskSaveChanges(    &dialogOptions,
  316.                                 action,
  317.                                 &reply,
  318.                                 eventUPP,
  319.                                 (NavCallBackUserData)&gDocumentList);
  320.     
  321.     DisposeRoutineDescriptor(eventUPP);
  322.  
  323.     return reply;
  324. }
  325.  
  326.  
  327. // **********************************************************************
  328. // *
  329. // *    CloseDocument()
  330. // *
  331. // **********************************************************************
  332. void CloseDocument(Document* theDocument, Boolean quitting)
  333. {    
  334.     OSErr    theErr = noErr;
  335.     short    index;
  336.     Str255    theName;
  337.  
  338.     index = 0;
  339.     while ((gDocumentList[index] != theDocument) && (index < kMaxDocumentCount))
  340.         index++;
  341.  
  342.     if (gDocumentList[index] == theDocument)
  343.         {
  344.         if (theDocument->dirty)
  345.             {
  346.             if (gNavServicesExists)
  347.                 {
  348.                 NavAskSaveChangesResult result = 0;
  349.             GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  350.             result = OpenAskSaveChanges(theName,quitting);
  351.             switch (result)
  352.                 {
  353.                 case kNavAskSaveChangesSave:
  354.                     if (!DoSaveDocument(theDocument))
  355.                         {
  356.                         gQuitting = false;    // don't quit yet!
  357.                         //return;
  358.                         }
  359.                     break;
  360.                 case kNavAskSaveChangesCancel:
  361.                     gQuitting = false;    // don't quit yet!
  362.                     //return;
  363.                     break;
  364.                 }
  365.             if (result == kNavAskSaveChangesCancel)
  366.                 return;    // don't close the document
  367.             }
  368.             else
  369.                 {
  370.                 short response = 0;
  371.                 Str255 theVerb;
  372.                 GetWTitle(theDocument->theWindow,(unsigned char*)&theName);
  373.                 GetIndString((unsigned char*)&theVerb,rAppStringsID,(gQuitting) ? slQuittingIndex : slClosingIndex);
  374.                 ParamText((ConstStr255Param)&theName,(ConstStr255Param)&theVerb,(ConstStr255Param)"\p",(ConstStr255Param)"\p");
  375.                 SetCursor(&qd.arrow);
  376.                 response = Alert(rSaveChangesID,0L);
  377.  
  378.                 if (response == 1)
  379.                     {            // Save
  380.                     if (!DoSaveDocument(theDocument))
  381.                         {
  382.                         gQuitting = false;
  383.                         return;
  384.                         }
  385.                     }
  386.                 else
  387.                     if (response == 3)
  388.                         {    // Don't Save
  389.                         ;
  390.                         }
  391.                     else
  392.                         {    // Cancel
  393.                         gQuitting = false;
  394.                         return;
  395.                         }
  396.                 }
  397.             }
  398.  
  399.         if (theDocument->fRefNum)
  400.             FSClose(theDocument->fRefNum);
  401.  
  402.         if (gCanDrag && theDocument->theTE != NULL)
  403.             {
  404.             theErr = RemoveReceiveHandler(receiveHandler,theDocument->theWindow);
  405.             theErr = RemoveTrackingHandler(trackingHandler,theDocument->theWindow);
  406.             }
  407.         
  408.         if (theDocument->theTE != NULL)
  409.             {
  410.             DisposeRgn(theDocument->hiliteRgn);
  411.             TEDispose(theDocument->theTE);
  412.             
  413.             if (theDocument->undoDragText)
  414.                 {
  415.                 DisposeHandle(theDocument->undoDragText);
  416.                 theDocument->undoDragText = 0L;
  417.                 }
  418.             }
  419.         else
  420.             {
  421.             if (theDocument->fPict != NULL)
  422.                 KillPicture((PicHandle)theDocument->fPict);    
  423.             if (theDocument->fHeader != NULL)
  424.                 DisposeHandle(theDocument->fHeader);
  425.             }
  426.  
  427.         DisposeWindow(theDocument->theWindow);
  428.  
  429.         while (index < kMaxDocumentCount)
  430.             {
  431.             gDocumentList[index] = gDocumentList[index + 1];
  432.             index++;
  433.             }
  434.  
  435.         DisposePtr((Ptr)theDocument);
  436.         gDocumentCount--;
  437.     }
  438. }
  439.  
  440.  
  441. // **********************************************************************
  442. // *
  443. // *    DoActivateDocument()
  444. // *
  445. // **********************************************************************
  446. void DoActivateDocument(Document* theDocument, short activate)
  447. {    
  448.     if (theDocument->theTE != NULL)
  449.         {
  450.         if (activate)
  451.             {
  452.             TEActivate(theDocument->theTE);
  453.             HiliteControl(theDocument->vScroll,0);
  454.             HiliteControl(theDocument->hScroll,0);
  455.             DoDrawGrowIcon(theDocument->theWindow);
  456.             TEGetHiliteRgn(theDocument->hiliteRgn,theDocument->theTE);
  457.             }
  458.         else
  459.             {
  460.             TEDeactivate(theDocument->theTE);
  461.             HiliteControl(theDocument->vScroll,255);
  462.             HiliteControl(theDocument->hScroll,255);
  463.             DoDrawGrowIcon(theDocument->theWindow);
  464.             }
  465.         }
  466. }
  467.  
  468.  
  469. // **********************************************************************
  470. // *
  471. // *    IsDocumentWindow()
  472. // *
  473. // **********************************************************************
  474. Document* IsDocumentWindow(WindowPtr theWindow)
  475. {    
  476.     short        index = 0;
  477.     Document*    theDocument;
  478.  
  479.     theDocument = (Document*)GetWRefCon(theWindow);
  480.  
  481.     while ((gDocumentList[index] != theDocument) && (index < gDocumentCount))
  482.         index++;
  483.  
  484.     if (gDocumentList[index] == theDocument)
  485.         return(theDocument);
  486.     else
  487.         return((Document*)0L);
  488. }
  489.  
  490.  
  491. // **********************************************************************
  492. // *
  493. // *    DoSelectAllDocument()
  494. // *
  495. // **********************************************************************
  496. void DoSelectAllDocument(Document* theDocument)
  497. {
  498.     if (theDocument && (theDocument->theTE))
  499.         TESetSelect(0,32767,theDocument->theTE);
  500. }
  501.  
  502.  
  503. // **********************************************************************
  504. // *
  505. // *    DisableUndoDrag()
  506. // *
  507. // **********************************************************************
  508. void DisableUndoDrag()
  509. {    
  510.     short        index;
  511.     Document*    theDoc;
  512.  
  513.     gCanUndoDrag = slCantUndo;
  514.  
  515.     index = gDocumentCount;
  516.     while (index--)
  517.         {
  518.         theDoc = gDocumentList[index];
  519.         if (theDoc->undoDragText)
  520.             {
  521.             DisposeHandle(theDoc->undoDragText);
  522.             theDoc->undoDragText = 0L;
  523.             }
  524.         }
  525. }
  526.  
  527.  
  528. // **********************************************************************
  529. // *
  530. // *    DoUndoDrag()
  531. // *
  532. // **********************************************************************
  533. void DoUndoDrag()
  534. {    
  535.     short        index, selStart, selEnd;
  536.     Document*    theDoc;
  537.     Handle        theText;
  538.     WindowPtr    theWindow;
  539.     Rect        theRect;
  540.  
  541.     if (gCanUndoDrag != slCantUndo)
  542.         {
  543.         theWindow = 0L;
  544.         index = gDocumentCount;
  545.         while (index--)
  546.             {
  547.             theDoc = gDocumentList[index];
  548.  
  549.             SetPort(theDoc->theWindow);
  550.             
  551.             if (theText = theDoc->undoDragText)
  552.                 {
  553.                 Rect        bounds = theDoc->theWindow->portRect;
  554.  
  555.                 theDoc->undoDragText = (**theDoc->theTE).hText;
  556.                 (**theDoc->theTE).hText = theText;
  557.  
  558.                 TECalText(theDoc->theTE);
  559.  
  560.                 selStart = theDoc->undoSelStart;
  561.                 selEnd   = theDoc->undoSelEnd;
  562.                 TESetSelect(selStart,selEnd,theDoc->theTE);
  563.                 theDoc->undoSelStart = theDoc->lastSelStart;
  564.                 theDoc->undoSelEnd   = theDoc->lastSelEnd;
  565.                 theDoc->lastSelStart = selStart;
  566.                 theDoc->lastSelEnd   = selEnd;
  567.  
  568.                 theRect = bounds;
  569.                 theRect.right  -= 15;
  570.                 theRect.bottom -= 15;
  571.                 EraseRect(&theRect);
  572.                 TEUpdate(&theRect,theDoc->theTE);
  573.                 }
  574.             }
  575.  
  576.         if (gCanUndoDrag == slUndoDrag)
  577.             gCanUndoDrag = slRedoDrag;
  578.         else
  579.             gCanUndoDrag = slUndoDrag;
  580.  
  581.         theWindow = gUndoFrontmost;
  582.         gUndoFrontmost = gLastFrontmost;
  583.         gLastFrontmost = theWindow;
  584.         }
  585. }
  586.  
  587.  
  588. // *****************************************************************************
  589. // *
  590. // *    DoDrawGrowIcon()
  591. // *
  592. // *****************************************************************************
  593. void DoDrawGrowIcon(WindowPtr theWindow)
  594. {
  595.     RgnHandle saveClipRgn = NewRgn();
  596.     Rect tempRect;
  597.  
  598.     if (saveClipRgn)
  599.         {
  600.         GetClip(saveClipRgn);
  601.     
  602.         SetRect(&tempRect,
  603.                 theWindow->portRect.right-15,
  604.                 theWindow->portRect.bottom-15,
  605.                 theWindow->portRect.right,
  606.                 theWindow->portRect.bottom);
  607.         ClipRect(&tempRect);
  608.         DrawGrowIcon(theWindow);
  609.         
  610.         SetClip(saveClipRgn);
  611.         DisposeRgn(saveClipRgn);
  612.         }
  613.     else
  614.         DrawGrowIcon(theWindow);
  615. }
  616.  
  617.  
  618. // *****************************************************************************
  619. // *
  620. // *    UpdateWindow()
  621. // *
  622. // *    Update event is received for a document window.
  623. // *
  624. // *****************************************************************************
  625. void UpdateWindow(Document* theDocument)
  626. {    
  627.     WindowPtr     theWindow = theDocument->theWindow;
  628.     Rect        bounds = theDocument->theWindow->portRect;
  629.     
  630.     SetPort(theWindow);
  631.     
  632.     BeginUpdate(theWindow);
  633.  
  634.     EraseRect(&bounds);
  635.     if (theDocument->theTE != NULL)
  636.         {
  637.         DrawControls(theWindow);
  638.         DoDrawGrowIcon(theWindow);
  639.         if (theDocument->theTE)
  640.             TEUpdate(&bounds,theDocument->theTE);
  641.         }
  642.     else
  643.         {
  644.         if (theDocument->fPict != NULL)
  645.             DrawPicture((PicHandle)theDocument->fPict,&((**((PicHandle)theDocument->fPict)).picFrame));
  646.         }
  647.     EndUpdate(theWindow);
  648. }
  649.  
  650.  
  651. // *****************************************************************************
  652. // *
  653. // *    DoZoomDocument()
  654. // *
  655. // *****************************************************************************
  656. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart)
  657. {
  658.     GrafPtr    oldPort;
  659.     GetPort(&oldPort);
  660.     
  661.     SetPort(theWindow);
  662.     EraseRect(&theWindow->portRect);
  663.     ZoomWindow(theWindow,thePart,theWindow == FrontWindow());
  664.     
  665.     if (theDocument->theTE != NULL)
  666.         {
  667.         PositionDocumentParts((Document*)GetWRefCon(theWindow));
  668.         AdjustScrollBar((Document*)GetWRefCon(theWindow));
  669.         DoDrawGrowIcon(theWindow);
  670.         }
  671.  
  672.     InvalRect(&theWindow->portRect);
  673.  
  674.     SetPort(oldPort);
  675. }
  676.  
  677.  
  678. // *****************************************************************************
  679. // *
  680. // *    GrowDocumentWindow()
  681. // *
  682. // *****************************************************************************
  683. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint)
  684. {    
  685.     long    result;
  686.     Rect    sizeRect;
  687.     Rect    bounds = theWindow->portRect;
  688.  
  689.     SetPort(theWindow);
  690.     
  691.     sizeRect = qd.screenBits.bounds;
  692.     if (!(result = GrowWindow(theWindow,thePoint,&sizeRect)))
  693.         return;
  694.         
  695.     SizeWindow(theWindow,LoWord(result),HiWord(result),false);
  696.  
  697.     PositionDocumentParts((Document*)GetWRefCon(theWindow));
  698.  
  699.     AdjustScrollBar((Document*)GetWRefCon(theWindow));
  700.  
  701.     DoDrawGrowIcon(theWindow);
  702.  
  703.     bounds = theWindow->portRect;
  704.     InvalRect(&bounds);
  705. }